﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Web;
using System.ServiceModel.Description;
using System.ServiceModel;
using CORSSupport;
using Serveur.DataFactory;

namespace SessionServiceHost
{
    class Program
    {
        static void Main(string[] args)
        {
            WebHttpBinding webBind = new WebHttpBinding();

            webBind.CrossDomainScriptAccessEnabled = true;

            CorsEnabledServiceHost Dhost = new CorsEnabledServiceHost(typeof(RESTDataService.RESTDataService), new Uri[] { new Uri("http://localhost:8084/") });
            CorsEnabledServiceHost Shost = new CorsEnabledServiceHost(typeof(RESTSessionService.RESTSessionService), new Uri[] { new Uri("http://localhost:8042/") });
            //ServiceEndpoint ep = host.AddServiceEndpoint(typeof(SessionService.ISessionService), webBind, "");

            //host.AddDefaultEndpoints();
            ServiceDebugBehavior Dsdb = Dhost.Description.Behaviors.Find<ServiceDebugBehavior>();
            Dsdb.HttpHelpPageEnabled = false;
            Dsdb.IncludeExceptionDetailInFaults = true;

            ServiceDebugBehavior Ssdb = Dhost.Description.Behaviors.Find<ServiceDebugBehavior>();
            Ssdb.HttpHelpPageEnabled = false;
            Ssdb.IncludeExceptionDetailInFaults = true;

            Dhost.Open();
            Shost.Open();
            
            Console.WriteLine("Host ok.");
            if (Console.ReadLine() == "populate")
            {
                Populator.Populate();
            }
            Dhost.Close();
            Shost.Close();
        }
    }
}
